﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace RSSP1
{
	class HD_Rssp1
	{
		/*返回值*/
		public enum EnumReturn
		{
			EnumReturnTrue = 0x55,
			EnumReturnFalse = 0xAA,
			EnumReturnNull = 0x00
		}

		[StructLayout(LayoutKind.Sequential)]
		public struct Data_Buff
		{
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
			public byte[] send_data;                    /*发送使用数据*/
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]
			public byte[] buff_source;                  /*原始数据*/
			public ushort send_buff_length;             /*转换后数据长度*/
		}

		[DllImport("Rssp1Lib.dll", CallingConvention = CallingConvention.Cdecl)]
		public static extern void HD_InitRssp1Conn();
		[DllImport("Rssp1Lib.dll", CallingConvention = CallingConvention.Cdecl)]
		public static extern void HD_AddRssp1Conn(UInt32 t_u32SrcId, UInt32 t_u32DstId);
		[DllImport("Rssp1Lib.dll", CallingConvention = CallingConvention.Cdecl)]
		public static extern EnumReturn HD_Rssp1Rec(UInt32 t_u32Rssp1SrcId, UInt32 t_u32Rssp1DestId, UInt32 t_u32CycleNum,
			byte[] p_u8RcvBuff, ref UInt16 p_u16RcvLen, ref UInt32 p_u32Err, ref byte p_u8CommFlag);
		[DllImport("Rssp1Lib.dll", CallingConvention = CallingConvention.Cdecl)]
		public static extern byte HD_Rssp1Snd(
	        UInt32 t_u32Rssp1SrcId,
	        UInt32 t_u32Rssp1DestId,
	        ref UInt32 p_p32IsSseOrSsr,
	        UInt32 t_u32CycleNum,
	        byte[] p_p8SendBuff,
	        ref UInt16 p_p16SendLen,
	        ref UInt32 p_u32Err);

		public static string RSSPI_GetRssp1Type(byte type1, byte type2)
		{
			string RsspType = "";
			if (((0x01 == type1) && (0x80 == type2)) || ((0x02 == type1) && (0x81 == type2)))
			{
				RsspType = "RSD";
			}
			else if ((0x01 == type1) && (0x90 == type2))
			{
				RsspType = "SSE";
			}
			else if ((0x01 == type1) && (0x91 == type2))
			{
				RsspType = "SSR";
			}
			else
			{
				RsspType = "ERR";
			}
			return RsspType;
		}
	}

	

}
